/**
 * Created by IntelliJ IDEA.
 * User: joa
 * Date: 11/22/10
 * Time: 4:34 PM
 * To change this template use File | Settings | File Templates.
 */
package org.osflash.signals;

import flash.display.Sprite;
import flash.events.Event;
import flash.system.System;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.utils.GetTimer;

@:meta(SWF(width=800,height=600,frameRate=64,backgroundColor=0x333333))
class RemovePerformance extends Sprite {

	var _out0 : TextField;
	var _out1 : TextField;
	var _s : ISignal;
	var _t0 : Int;
	var _f : Int;
	var _min : Int;
	var _max : Int;
	public function new() {
		_out0 = new TextField();
		_out0.defaultTextFormat = new TextFormat("arial", 24, 0xff00ff);
		_out0.autoSize = TextFieldAutoSize.LEFT;
		_out0.x = 0x20;
		_out0.y = 0x20;
		_out1 = new TextField();
		_out1.defaultTextFormat = new TextFormat("arial", 24, 0xff00ff);
		_out1.autoSize = TextFieldAutoSize.LEFT;
		_out1.x = 0x200;
		_out1.y = 0x20;
		_s = new Signal();
		addChild(_out0);
		addChild(_out1);
		addEventListener(Event.ENTER_FRAME, onEnterFrame);
	}

	function onEnterFrame(event : Event) : Void {
		var t1 : Int = getTimer();
		if((t1 - _t0) >= 1000)  {
			_out0.text = _f + "fps
" + (System.totalMemory >> 20) + "mb
" + _min + "ms
" + _max + "ms";
			_f = 0;
			_t0 = t1;
		}
		_f++;
		var n : Int = 5000 / 4;
		var m0 : Int = getTimer();
		while(--n != 0) {
			_s.dispatch();
			_s.add(l0);
			//2**(4-1)=8
			_s.add(l1);
			_s.add(l2);
			_s.add(l3);
			_s.add(l4);
			_s.add(l5);
			_s.add(l6);
			_s.add(l7);
		}

		var dt : Int = (getTimer() - m0);
		if(dt < _min) _min = dt;
		if(dt > _max) _max = dt;
		_out1.text = dt + "ms";
	}

	function l0() : Void {
		_s.remove(l0);
	}

	function l1() : Void {
		_s.remove(l1);
	}

	function l2() : Void {
		_s.remove(l2);
	}

	function l3() : Void {
		_s.remove(l3);
	}

	function l4() : Void {
		_s.remove(l4);
	}

	function l5() : Void {
		_s.remove(l5);
	}

	function l6() : Void {
		_s.remove(l6);
	}

	function l7() : Void {
		_s.remove(l7);
	}

}

